<template>
  <!-- 客户账单统计 -->
  <el-container>
    <el-header>
      <div class="left-panel">
        <el-button
          type="primary"
          icon="el-icon-plus"
          @click="handleExport"
          v-auth-button="['export/statementBill']"
          >导出</el-button
        >
      </div>
      <div class="right-panel">
        <div class="right-panel-search">
          <sc-table-select
            style="width: 100%"
            v-model="searchSelectCustomer"
            :apiObj="apiObjCustomer"
            :table-width="700"
            clearable
            collapse-tags
            collapse-tags-tooltip
            :props="props"
            :params="customerForm"
            @change="changeCustomer"
          >
            <template #header="{ form, submit }">
              <el-form :model="customerForm">
                <el-row :gutter="20">
                  <el-col :span="8">
                    <el-input
                      v-model="customerForm.name"
                      placeholder="客户名称"
                      clearable
                      style="width: 100%"
                    ></el-input>
                  </el-col>
                  <el-col :span="6">
                    <el-date-picker
                      v-model="customerForm.year"
                      value-format="YYYY"
                      type="date"
                      placeholder="请选择统计年份"
                      :teleported="false"
                      style="width: 100%"
                    ></el-date-picker>
                  </el-col>
                  <el-col :span="6">
                    <el-date-picker
                      v-model="customerForm.endTime"
                      value-format="YYYY-MM-DD"
                      type="date"
                      placeholder="结束时间"
                      :teleported="false"
                      style="width: 100%"
                    ></el-date-picker>
                  </el-col>
                  <el-col :span="4">
                    <el-form-item width="100%">
                      <el-button type="primary" @click="submit">查询</el-button>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-form>
              <!-- <el-alert title="自定义FORM插糟 传递了form对象和提交方法" type="info" /> -->
            </template>
            <el-table-column
              prop="customerName"
              label="客户名称"
              min-width="150"
            ></el-table-column>
            <el-table-column
              prop="numbers"
              label="合同成交量"
              min-width="150"
            ></el-table-column>
          </sc-table-select>
          <!-- <el-select
            v-if="userList.length != 0"
            v-model="searchValue.adminId"
            placeholder="请选择业务员"
            style="width: 100%"
            clearable
            filterable
          >
            <el-option
              v-for="item in userList"
              :key="item.id"
              :label="item.username"
              :value="item.id"
            />
          </el-select> -->
          <el-date-picker
            v-model="searchValue.year"
            type="year"
            placeholder="请选择年份,默认当前年"
            value-format="YYYY"
            style="width: 100%"
          >
          </el-date-picker>
          <el-button
            type="primary"
            icon="el-icon-search"
            @click="upsearch"
          ></el-button>
        </div>
      </div>
    </el-header>
    <el-main class="nopadding">
      <scTable ref="table" :apiObj="apiObj" row-key="id" stripe>
        <!-- <el-table-column label="ID" prop="id" width="50"></el-table-column> -->
        <el-table-column
          label="客户"
          prop="customerName"
          min-width="150"
          fixed="left"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column label="1月" min-width="100">
          <template #default="scope">
            <p style="color: #409eff">应收:{{ scope.row.actualMoney1 }}</p>
            <p style="color: #2bd814">
              实收:{{ scope.row.customerPaymentMoney1 }}
            </p>
            <p style="color: #f56c6c">
              欠款:{{
                scope.row.actualMoney1 - scope.row.customerPaymentMoney1
              }}
            </p>
          </template>
        </el-table-column>
        <el-table-column label="2月" min-width="100">
          <template #default="scope">
            <p style="color: #409eff">应收:{{ scope.row.actualMoney2 }}</p>
            <p style="color: #2bd814">
              实收:{{ scope.row.customerPaymentMoney2 }}
            </p>
            <p style="color: #f56c6c">
              欠款:{{
                scope.row.actualMoney2 - scope.row.customerPaymentMoney2
              }}
            </p>
          </template>
        </el-table-column>
        <el-table-column label="3月" min-width="100">
          <template #default="scope">
            <p style="color: #409eff">应收:{{ scope.row.actualMoney3 }}</p>
            <p style="color: #2bd814">
              实收:{{ scope.row.customerPaymentMoney3 }}
            </p>
            <p style="color: #f56c6c">
              欠款:{{
                scope.row.actualMoney3 - scope.row.customerPaymentMoney3
              }}
            </p>
          </template>
        </el-table-column>
        <el-table-column label="4月" min-width="100">
          <template #default="scope">
            <p style="color: #409eff">应收:{{ scope.row.actualMoney4 }}</p>
            <p style="color: #2bd814">
              实收:{{ scope.row.customerPaymentMoney4 }}
            </p>
            <p style="color: #f56c6c">
              欠款:{{
                scope.row.actualMoney4 - scope.row.customerPaymentMoney4
              }}
            </p>
          </template>
        </el-table-column>
        <el-table-column label="5月" min-width="100">
          <template #default="scope">
            <p style="color: #409eff">应收:{{ scope.row.actualMoney5 }}</p>
            <p style="color: #2bd814">
              实收:{{ scope.row.customerPaymentMoney5 }}
            </p>
            <p style="color: #f56c6c">
              欠款:{{
                scope.row.actualMoney5 - scope.row.customerPaymentMoney5
              }}
            </p>
          </template>
        </el-table-column>
        <el-table-column label="6月" min-width="100">
          <template #default="scope">
            <p style="color: #409eff">应收:{{ scope.row.actualMoney6 }}</p>
            <p style="color: #2bd814">
              实收:{{ scope.row.customerPaymentMoney6 }}
            </p>
            <p style="color: #f56c6c">
              欠款:{{
                scope.row.actualMoney6 - scope.row.customerPaymentMoney6
              }}
            </p>
          </template>
        </el-table-column>
        <el-table-column label="7月" min-width="100">
          <template #default="scope">
            <p style="color: #409eff">应收:{{ scope.row.actualMoney7 }}</p>
            <p style="color: #2bd814">
              实收:{{ scope.row.customerPaymentMoney7 }}
            </p>
            <p style="color: #f56c6c">
              欠款:{{
                scope.row.actualMoney7 - scope.row.customerPaymentMoney7
              }}
            </p>
          </template>
        </el-table-column>
        <el-table-column label="8月" min-width="100">
          <template #default="scope">
            <p style="color: #409eff">应收:{{ scope.row.actualMoney8 }}</p>
            <p style="color: #2bd814">
              实收:{{ scope.row.customerPaymentMoney8 }}
            </p>
            <p style="color: #f56c6c">
              欠款:{{
                scope.row.actualMoney8 - scope.row.customerPaymentMoney8
              }}
            </p>
          </template>
        </el-table-column>
        <el-table-column label="9月" min-width="100">
          <template #default="scope">
            <p style="color: #409eff">应收:{{ scope.row.actualMoney9 }}</p>
            <p style="color: #2bd814">
              实收:{{ scope.row.customerPaymentMoney9 }}
            </p>
            <p style="color: #f56c6c">
              欠款:{{
                scope.row.actualMoney9 - scope.row.customerPaymentMoney9
              }}
            </p>
          </template>
        </el-table-column>
        <el-table-column label="10月" min-width="100">
          <template #default="scope">
            <p style="color: #409eff">应收:{{ scope.row.actualMoney10 }}</p>
            <p style="color: #2bd814">
              实收:{{ scope.row.customerPaymentMoney10 }}
            </p>
            <p style="color: #f56c6c">
              欠款:{{
                scope.row.actualMoney10 - scope.row.customerPaymentMoney10
              }}
            </p>
          </template>
        </el-table-column>
        <el-table-column label="11月" min-width="100">
          <template #default="scope">
            <p style="color: #409eff">应收:{{ scope.row.actualMoney11 }}</p>
            <p style="color: #2bd814">
              实收:{{ scope.row.customerPaymentMoney11 }}
            </p>
            <p style="color: #f56c6c">
              欠款:{{
                scope.row.actualMoney11 - scope.row.customerPaymentMoney11
              }}
            </p>
          </template>
        </el-table-column>
        <el-table-column label="12月" min-width="100">
          <template #default="scope">
            <p style="color: #409eff">应收:{{ scope.row.actualMoney12 }}</p>
            <p style="color: #2bd814">
              实收:{{ scope.row.customerPaymentMoney12 }}
            </p>
            <p style="color: #f56c6c">
              欠款:{{
                scope.row.actualMoney12 - scope.row.customerPaymentMoney12
              }}
            </p>
          </template>
        </el-table-column>
        <el-table-column label="累计" fixed="right" min-width="100">
          <template #default="scope">
            <p style="color: #409eff">应收:{{ scope.row.actualMoney13 }}</p>
            <p style="color: #2bd814">
              实收:{{ scope.row.customerPaymentMoney13 }}
            </p>
            <p style="color: #f56c6c">
              欠款:{{
                scope.row.actualMoney13 - scope.row.customerPaymentMoney13
              }}
            </p>
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" align="center" width="120">
          <template #default="scope">
            <el-button-group>
              <el-button
                text
                type="primary"
                size="small"
                @click="table_show(scope.row, scope.$index)"
                >查看账单明细</el-button
              >
            </el-button-group>
          </template>
        </el-table-column>
      </scTable>
    </el-main>
  </el-container>
</template>

<script>
import { exportFile } from "@/utils/exportFile"
export default {
  name: "statementBill",
  data () {
    return {
      apiObj: this.$API.reportForm.getStatementBillList,
      searchValue: {
        customerId: '',//客户id
        year: "",
      },
      apiObjCustomer: this.$API.finance.plancollect.getCustomerNumbers,
      customerForm: {
        name: null,
        startTime: null,
        endTime: null,
      },
      props: {
        label: "customerName",
        value: "id",
      },
      searchSelectCustomer: {},
      columnsFilters: ["money"],
      countMoney: {},
      userList: [],
      userInfo: {},
    }
  },
  mounted () {
    this.userInfo = this.$TOOL.data.get("USER_INFO")
    this.searchValue.year = new Date().getFullYear()
  },
  methods: {
    // 导出
    async handleExport () {
      let res = await this.$API.reportForm.exportCustomerMonthMoney.get(this.searchValue)
      exportFile(res, '客户账单统计.xls')
    },
    async getUserList () {
      let res = await this.$API.user.getUserList.get({ page: 1, limit: 1000 })
      this.userList = res.data
    },

    changeCustomer (val) {
      this.searchValue.customerId = val.id
    },
    // 查看账单明细
    table_show (row) {
      this.$router.push({
        // path: '/contract/contractManagement/contractDetail',
        path: "/reportForm/customerBill",
        query: {
          customerId: row.customerId,
          customerName: row.customerName
        },
      })
    },
    //搜索
    upsearch () {
      // this.getCountMoney()
      this.$refs.table.upData(this.searchValue)
    },
    //本地更新数据
    handleSaveSuccess () {
      this.$refs.table.refresh()
    },
    // 双击表格
    handleRowDblclick (row) {
      this.table_show(row)
    },
  },
};
</script>

<style lang="scss" scoped>
.count {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  height: 50px;
  padding-left: 12px;
  font-size: 14px;
  color: #555;
  font-weight: 600;
  p {
    margin-right: 20px;
  }
}
</style>
